package cn.fl.project.service.impl;

import cmm.comm.facade.framework.api.ISysCdMapApiService;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.api.ISysRegionApiService;
import cmm.comm.facade.framework.condition.SysCdMapDQueryCondition;
import cmm.comm.facade.framework.dto.SysCdMapDDTO;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.framework.dto.SysRegionDTO;
import cmm.comm.facade.upload.api.ISysUlDatCfgDtlApiService;
import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlDatCfgDtlQueryCondition;
import cmm.comm.facade.upload.dto.SysUlDatCfgDtlDTO;
import cmm.mid.core.framework.dto.BaseParamDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.dto.SysOrgDTO;
import cmm.user.facade.system.dto.SysUsrDTO;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.service.ICstCorpTeamService;
import cn.fl.customer.service.ICstNpBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.customer.vo.CstCorpTeamVO;
import cn.fl.customer.vo.CstNpBscInfoVO;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.base.lnkcomp.vo.BasePrjLnkCompVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.project.api.IProjectQueryApiService;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjCstBscInfoConstant;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjLnkCompService;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.transform.PrjLinkFlowSHVOTransform;
import cn.fl.project.transform.PrjLnkCompVOTransform;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjLinkFlowSHVO;
import cn.fl.project.vo.PrjLnkCompVO;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import cn.fl.system.transform.SysUlFilesRecVOTransform;
import cn.fl.system.vo.SysUlFilesRecVO;

import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.fastjson.JSON;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.customer.facade.customer.condition.CstCorpTeamQueryCondition;
import fl.customer.facade.customer.constant.CustomerConstant;
import fl.flow.facade.flow.api.IFlowApiService;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowManageVQueryCondition;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.flow.facade.flow.dto.SysFlowManageVDTO;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.riskctrl.facade.externalinterface.service.api.IExternalRcCstBscInfoSearchApiService;
import fl.riskctrl.facade.riskctrl.condition.RcCstBscInfoCarQC;
import fl.riskctrl.facade.riskctrl.dto.RcCstBscInfoDTO;
import fl.riskctrl.facade.riskctrl.rccstchannelinfo.dto.RcCstChannelInfoDTO;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.CommonAudStsCdEnum;
import fl.spl.facade.framework.enums.LnkCompFileCfgEnum;
import fl.spl.facade.framework.enums.SplAudStsCdEnum;
import fl.spl.facade.lnkcomp.api.ILnkCompModApiService;
import fl.spl.facade.lnkcomp.api.ILnkCompModDtlApiService;
import fl.spl.facade.lnkcomp.api.IPrjLnkCompApiService;
import fl.spl.facade.lnkcomp.api.IPrjLnkCompQueryApiService;
import fl.spl.facade.lnkcomp.condition.LnkCompModDtlQC;
import fl.spl.facade.lnkcomp.condition.LnkCompModQC;
import fl.spl.facade.lnkcomp.condition.PrjLnkCompQueryCondition;
import fl.spl.facade.lnkcomp.constant.LnkCompFlowConstant;
import fl.spl.facade.lnkcomp.constant.PrjLnkCompRelInfoConstant;
import fl.spl.facade.lnkcomp.constant.LnkCompConstant;
import fl.spl.facade.lnkcomp.dto.LnkCompModDTO;
import fl.spl.facade.lnkcomp.dto.LnkCompModDtlDTO;
import fl.spl.facade.lnkcomp.dto.PrjLnkCompDTO;
import fl.spl.facade.spl.api.ISplCommPropInfoApiService;
import fl.spl.facade.spl.dto.SplCommPropInfoDTO;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.util.*;

import static cn.fl.capital.constant.CapAdvFundConstant.SYSCD;

/**
 * @Description: 挂靠公司表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get*
 *               批量：batch* 查询集合：search*
 */
@Service
public class PrjLnkCompServiceImpl implements IPrjLnkCompService {
	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IPrjLnkCompService.class);


	/**
	 * 组织机构 暴露服务
	 */
	@Autowired
	private ISysOrgApiService sysOrgApiService;
	/**
	 * 字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	@Autowired
	private ISysCdMapApiService sysCdMapApiService;
	/**
	 * 字典服务
	 */
	@Autowired
	private IUploadApiService uploadApiService;
	
	/**
	 * 流程API接口服务
	 */
	@Autowired
	private IFlowApiService flowApiService;

	@Autowired
	private ISysRegionApiService sysRegionApiService ;

	@Autowired
	private IPrjLnkCompApiService prjLnkCompApiService ;

	@Autowired
	private IPrjLnkCompQueryApiService prjLnkCompQueryApiService ;

	@Autowired
	private ISplCommPropInfoApiService splCommPropInfoApiService;

	@Autowired
	private ISysUsrApiService sysUsrApiService;
	@Autowired
	private ILnkCompModDtlApiService lnkCompModDtlApiService ;
	
	@Autowired
	private ILnkCompModApiService lnkCompModApiService ;
	
	@Autowired
	private IFlowQueryApiService flowQueryApiService ;
	@Autowired
	private ISysUlDatCfgDtlApiService sysUlDatCfgDtlApiService;
	
	@Autowired
	private IProjectQueryApiService projectQueryApiService ;

	@Autowired
	private IExternalRcCstBscInfoSearchApiService externalRcCstBscInfoSearchApiService;

	@Autowired
	private IPrjBscInfoService prjBscInfoService;

	@Autowired
	private ICstBscInfoService cstBscInfoService;

	@Autowired
	private ICstCorpTeamService cstCorpTeamService;

	@Autowired
	private ICstNpBscInfoService cstNpBscInfoService;

	@Autowired
	private IPrjPrdBscInfoService prjPrdBscInfoService;

	@Override
	public int updateBlackList(String id, String blackList) {
		if(StringUtils.isNotBlank(id) && StringUtils.isNotBlank(blackList)){
			//return projectApiService.updateBlackList(id,blackList);
			return this.prjLnkCompApiService.updateBlackList(id,blackList);
		}
		return 0;
	}
	@Override
	public PrjLnkCompVO selectById(Long id) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			BaseLogUtils.newWebLogger("主键参数不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}
		//PrjLnkCompDTO dto = this.projectApiService.selectPrjLnkCompById(id);
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompById(id) ;
		/*Map<String, String> dictMap = this.sysDictionaryApiService
				.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentBuOrgCd(),
						DictionaryConstant.CODE_AUD_STS_CD);
		String audiCd = "";*/
		String ownerCdNm = "";
		/*if (!dictMap.isEmpty()) {
			audiCd = dictMap.get(dto.getAudStsCd());// 获取审核状态
		}*/
		Map<String, String> ownerCddictMap = this.sysDictionaryApiService
				.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentBuOrgCd(),
						DictionaryConstant.CODE_PRJ_OWNER_CD);
		if (!ownerCddictMap.isEmpty()) {
			ownerCdNm = ownerCddictMap.get(dto.getOwnerCd());// 获取审核状态
		}
		dto.setOwnerCdNm(ownerCdNm);// 挂靠公司归属名称
		/*dto.setAudStsCdNm(audiCd);*/
		return PrjLnkCompVOTransform.toVO(dto);
	}

	@Override
	public Long add(PrjLnkCompVO entity) throws BaseException {
		if (null == entity) {
			BaseLogUtils.newWebLogger("新增对象不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}

		/*Long id = this.projectApiService.addPrjLnkComp(
				PrjLnkCompVOTransform.toDTO(entity),
				CurrentThreadContext.getCurrentOrgCd(),
				CurrentThreadContext.getCurrentSysCd());*/
		Long id = this.prjLnkCompApiService.addPrjLnkComp(PrjLnkCompVOTransform.toDTO(entity),
				CurrentThreadContext.getCurrentOrgCd(),
				CurrentThreadContext.getCurrentSysCd());
		if (null != id) {
			List<SysUlFilesRecVO> fileList = entity.getFileList();
			if (CollectionUtils.isNotEmpty(fileList)) {
				for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
					sysUlFilesRecVO.setPkId(String.valueOf(id));
					//sysUlFilesRecVO.setTabNm("PRJ_LNK_COMP");
					sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
					if ("1".equals(entity.getOwnerCd())) {
						sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ030.getUploadRootPath())+sysUlFilesRecVO.getFilePath());
					} else if ("2".equals(entity.getOwnerCd())) {
						sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ029.getUploadRootPath())+sysUlFilesRecVO.getFilePath());
					} else {
						sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ032.getUploadRootPath())+sysUlFilesRecVO.getFilePath());
					}
					sysUlFilesRecVO.setCrtTm(new Date());
					sysUlFilesRecVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
					//默认验证状态:未验证
					sysUlFilesRecVO.setAudStsCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_GRP_VALID_STATUS_CD_A));

					/*sysUlFilesRecVO.setSysCd(CurrentThreadContext
							.getCurrentSysCd());
					sysUlFilesRecVO
							.setOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
					sysUlFilesRecVO
							.setCfgCd(PrjLnkCompConstant.PRJ_LNK_COMP_FILE_CODE);
					sysUlFilesRecVO
							.setCfgDtlCd(PrjLnkCompConstant.PRJ_LNK_COMP_FILE_DETAIL_CODE);*/
					/*this.uploadApiService
							.addSysUlFilesRec(SysUlFilesRecVOTransform
									.toDTO(sysUlFilesRecVO));*/
				}
				this.uploadApiService.addSysUlFilesRecList(SysUlFilesRecVOTransform.toDTOList(fileList));
			}
		}
		return id;
	}

	@Override
	public boolean removeById(Long id) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			BaseLogUtils.newWebLogger("删除主键参数不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return false;
		}
		//return this.projectApiService.removePrjLnkCompById(id);
		return this.prjLnkCompApiService.removePrjLnkCompById(id) ;
	}

	/**
	 * 删除
	 * 
	 * @param ids
	 * @return
	 */
	@Override
	public boolean removeByIds(List<Long> ids) throws BaseException {
		if (CollectionUtils.isEmpty(ids)) {
			BaseLogUtils.newWebLogger("删除主键参数集合不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return false;
		}
		//return projectApiService.removePrjLnkCompByIdList(ids);
		return this.prjLnkCompApiService.removePrjLnkCompByIdList(ids) ;
	}

	@Override
	public boolean modify(PrjLnkCompVO entity) throws BaseException {
		if (null == entity) {
			BaseLogUtils.newWebLogger("修改对象参数不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return false;
		}
		/*boolean flag = this.projectApiService.modifyPrjLnkComp(
				PrjLnkCompVOTransform.toDTO(entity),
				CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd());*/
		boolean flag = this.prjLnkCompApiService.modifyPrjLnkComp(PrjLnkCompVOTransform.toDTO(entity),
				CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd());
		if (flag) {
			List<SysUlFilesRecVO> fileList = entity.getFileList();
			List<SysUlFilesRecVO> modifyFileList = null;
			if (CollectionUtils.isNotEmpty(fileList)) {
				/*SysUlFilesRecQueryCondition ulQc = new SysUlFilesRecQueryCondition();
				ulQc.setPkId(String.valueOf(entity.getId()));
				this.uploadApiService.removeSysUlFilesRecByCondition(ulQc);*/
				Iterator<SysUlFilesRecVO> fileIterator = fileList.iterator();
				while (fileIterator.hasNext()) {
					SysUlFilesRecVO filesRecVO = fileIterator.next();
					if (StringUtils.isEmpty(filesRecVO.getId())) {
						filesRecVO.setPkId(String.valueOf(entity.getId()));
						filesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
						if ("1".equals(entity.getOwnerCd())) {
							filesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ030.getUploadRootPath())+filesRecVO.getFilePath());
						} else if ("2".equals(entity.getOwnerCd())) {
							filesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ029.getUploadRootPath())+filesRecVO.getFilePath());
						} else {
							filesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ032.getUploadRootPath())+filesRecVO.getFilePath());
						}
						filesRecVO.setCrtTm(new Date());
						filesRecVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
						//默认验证状态:未验证
						filesRecVO.setAudStsCd(PropertiesCacheUtils.getProperty(fl.constant.facade.framework.constant.DictionaryConstant.CODE_GRP_VALID_STATUS_CD_A));
					} else {
						fileIterator.remove();

                        if (CollectionUtils.isEmpty(modifyFileList)) {
                            modifyFileList = new ArrayList<>();
                        }
                        filesRecVO.setFilePath(null);//前台传来的文件路径会以http开头,文件路径不会改变,没有修改的必要,直接置空
						//String oldFilePath = filesRecVO.getFilePath();
						//filesRecVO.setFilePath(oldFilePath.substring(oldFilePath.indexOf(PropertiesCacheUtils.getProperty(LnkCompFileCfgEnum.PRJ029.getUploadCostomerPath()))));
						filesRecVO.setMdfTm(new Date());
                        filesRecVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
						modifyFileList.add(filesRecVO);
					}
				}
				/*for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
					if (StringUtils.isNotEmpty(sysUlFilesRecVO.getId())) {
						sysUlFilesRecVO.setPkId(String.valueOf(entity.getId()));
						sysUlFilesRecVO.setTabNm("PRJ_LNK_COMP");
						sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
						sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+sysUlFilesRecVO.getFilePath());
					} else {
						fileList.remove(sysUlFilesRecVO);//此处调用ArrayList.remove()之后继续循环会抛出java.util.ConcurrentModificationException
					}

					*//*sysUlFilesRecVO.setSysCd(CurrentThreadContext
							.getCurrentSysCd());
					sysUlFilesRecVO
							.setOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
					sysUlFilesRecVO
							.setCfgCd(PrjLnkCompConstant.PRJ_LNK_COMP_FILE_CODE);
					sysUlFilesRecVO
							.setCfgDtlCd(PrjLnkCompConstant.PRJ_LNK_COMP_FILE_DETAIL_CODE);
					sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH) + sysUlFilesRecVO.getFilePath());
					this.uploadApiService
							.addSysUlFilesRec(SysUlFilesRecVOTransform
									.toDTO(sysUlFilesRecVO));*//*
				}*/
				this.uploadApiService.addSysUlFilesRecList(SysUlFilesRecVOTransform.toDTOList(fileList));
				BaseLogUtils.newWebLogger("添加挂靠公司附件信息").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.setKeys("fileList", JSON.toJSONString(fileList))
						.info();
                if (CollectionUtils.isNotEmpty(modifyFileList)) {
                    this.uploadApiService.modifySysUlFilesRecList(SysUlFilesRecVOTransform.toDTOList(modifyFileList));
                }
				BaseLogUtils.newWebLogger("修改挂靠公司附件信息").setLogOperType(LogOperEnum.RESP)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.setKeys("modifyFileList", JSON.toJSONString(modifyFileList))
						.info();
            }
		}
		return flag;
	}
	

	@Override
	public Pager searchListPage(Pager page) throws BaseException {
		if (null == page)
			page = new Pager();
		Pager pager = null;
		//PrjLnkCompRlPsnQC qc = new PrjLnkCompRlPsnQC();
    	//qc.setTel("18879783516");
    	//this.projectQueryApiService.searchPrjLnkCompIdsByQC(qc,"11000","0000","001");
		//pager = this.projectApiService.searchPrjLnkCompListPage(page,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		pager = this.prjLnkCompQueryApiService.searchPrjLnkCompListPage(page,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		/*Map<String, String> dictMap = this.sysDictionaryApiService
				.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentBuOrgCd(),
						DictionaryConstant.CODE_AUD_STS_CD);
		if (null != pager && pager.getResultList() != null) {
			List<PrjLnkCompDTO> prjLnkCompList = (List<PrjLnkCompDTO>) pager
					.getResultList();
			if (CollectionUtils.isNotEmpty(prjLnkCompList)) {
				for (PrjLnkCompDTO comp : prjLnkCompList) {
					if (!dictMap.isEmpty()) {
						comp.setAudStsCdNm(dictMap.get(comp.getAudStsCd()));
					}
				}
			}
			pager.setResultList(prjLnkCompList);
		}*/
		if (null != pager && pager.getResultList() != null) {
			List<PrjLnkCompDTO> prjLnkCompList = (List<PrjLnkCompDTO>) pager
					.getResultList();
			if (CollectionUtils.isNotEmpty(prjLnkCompList)) {
				for (PrjLnkCompDTO prjLnkCompDTO : prjLnkCompList) {
					if (LnkCompFlowConstant.FLOW_MODEL_TYP_LNK_CHG.equals(prjLnkCompDTO.getBusTyp()) || LnkCompFlowConstant.FLOW_MODEL_TYP_LNK_GS_CHG.equals(prjLnkCompDTO.getBusTyp())) {
						if(CommonAudStsCdEnum.NOPASS.getStatus().equals(prjLnkCompDTO.getAudStsCd())){
							prjLnkCompDTO.setAudStsCd(CommonAudStsCdEnum.PASS.getStatus());
							prjLnkCompDTO.setAudStsCdNm(CommonAudStsCdEnum.PASS.getDesc());
						}
					}
				}
			}
			pager.setResultList(prjLnkCompList);
		}
		pager.setResultList(PrjLnkCompVOTransform
				.toVOList((List<PrjLnkCompDTO>) pager.getResultList()));
		return pager;
	}

	@Override
	public List<KeyValueVO> getAudStsCdList() throws BaseException {
		List<KeyValueVO> keyValueList = null;
		List<SysDictionaryDTO> dictionaryList = this.sysDictionaryApiService
				.searchGroup(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentOrgCd(),
						DictionaryConstant.CODE_AUD_STS_CD);
		if (CollectionUtils.isNotEmpty(dictionaryList)) {
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}

		return keyValueList;
	}

	@Override
	public List<KeyValueVO> getOwnerCdList() {
		List<KeyValueVO> keyValueList = null;
		List<SysDictionaryDTO> dictionaryList = this.sysDictionaryApiService
				.searchGroup(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentOrgCd(),
						DictionaryConstant.CODE_PRJ_OWNER_CD);
		if (CollectionUtils.isNotEmpty(dictionaryList)) {
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}

	@Override
	public List<PrjLnkCompVO> getPrjLnkCompByCondition(
			PrjLnkCompQueryCondition qc) {
		if(qc == null){
			return null;
		}
		/*return PrjLnkCompVOTransform.toVOList(this.projectApiService
				.getPrjLnkCompByCondition(qc));*/
		return PrjLnkCompVOTransform.toVOList(this.prjLnkCompQueryApiService.getPrjLnkCompByCondition(qc)) ;
	}

	@Override
	public List<KeyValueVO> getOrgCdList() throws BaseException {
		List<KeyValueVO> keyValueList = null;
		List<SysOrgDTO> list = this.sysOrgApiService
				.searchListByOrgTypCd(CurrentThreadContext.getCurrentSysCd());
		if (CollectionUtils.isNotEmpty(list)) {
			keyValueList = new ArrayList<>();
			for (SysOrgDTO sysOrgDTO : list) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysOrgDTO.getOrgCd());
				keyValue.setValue(sysOrgDTO.getOrgNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}

	@Override
	public boolean modifyAudStsCd(Long id, String audStsCd)
			throws BaseException {

		/*return this.projectApiService.modifyLnkCompAudStsCd(id, audStsCd,
				new Date(), CurrentThreadContext.getCurrentUserId());*/
		return this.prjLnkCompApiService.modifyLnkCompAudStsCd(id, audStsCd,
				new Date(), CurrentThreadContext.getCurrentUserId()) ;
	}

	@Override
	public DataResultVO addFlowStart(Long prjLnkCompId) {
		DataResultVO resultVO = new DataResultVO();
		if (null == prjLnkCompId) {
			throw new BaseException(
					BaseExceptionConstant.COMMON_0001,
					"请选择挂靠公司后发起流程！");
		}
		PrjLnkCompDTO dto = new PrjLnkCompDTO();
		FlowStartParamsDTO flowStartParamsDTO = this.getFlowStartParams(
				FlowConstant.FLOW_BUSINESS_TYP_LNK,
				FlowConstant.FLOW_MODEL_TYP_LNK);
		dto.setFlowStartParamsDTO(flowStartParamsDTO);
		dto.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		dto.setId(prjLnkCompId);
		/*DataResultDTO resultdto = this.projectApiService
				.addPrjLnkCompFlowStart(dto);*/
		DataResultDTO resultdto = this.prjLnkCompApiService.addPrjLnkCompFlowStart(dto) ;
		SysFlowManageVQueryCondition qc = new SysFlowManageVQueryCondition();
		qc.setModelTyp(FlowConstant.FLOW_MODEL_TYP_LNK_1);
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
        List<SysFlowManageVDTO> list = this.flowApiService.searchFlowManageVListForStart(qc);
        if(CollectionUtils.isNotEmpty(list)){
        	String pDefKey = list.get(0).getProcDefKey();
        	String pDefId = list.get(0).getProcDefId();
        	String pInstId = ((FlowStartedDTO)(resultdto.getData())).getProcInstanceId();
        	String pNo = ((FlowStartedDTO)(resultdto.getData())).getProcInstanceNo();
        	/*this.projectApiService.lnkCompFlowStartUpdateLnkCompBank(prjLnkCompId,
    				pDefKey, pDefId, pInstId, pNo,
    				CurrentThreadContext.getCurrentSysCd(),
    				CurrentThreadContext.getCurrentOrgCd(),
    				CurrentThreadContext.getCurrentBuOrgCd(),
    				CurrentThreadContext.getCurrentUserId());*/
        	this.prjLnkCompApiService.lnkCompFlowStartUpdateLnkCompBank(prjLnkCompId,
					pDefKey, pDefId, pInstId, pNo,
					CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd(),
					CurrentThreadContext.getCurrentBuOrgCd(),
					CurrentThreadContext.getCurrentUserId());
        }
		resultVO.setData(resultdto.getData());
		resultVO.setInfo(resultdto.getInfo());
		return resultVO;

	}

	/******************************************************
	 * 获取发起流程对象
	 * 
	 * @param businessType
	 *            :业务类型(FlowConstant.FLOW_BUSINESS_TYP_SETTLE)
	 * @param modelTyp
	 *            :流程业务分类 正常结清:FlowConstant.FLOW_MODEL_TYP_SETTLE_NORMAL
	 *            提前结清:FlowConstant.FLOW_MODEL_TYP_SETTLE_ADVANCE
	 *            强制结清:FlowConstant.FLOW_MODEL_TYP_SETTLE_FORCE
	 * @return
	 * @throws BaseException
	 *****************************************************/
	private FlowStartParamsDTO getFlowStartParams(String businessType,
			String modelTyp) throws BaseException {
		if (StringUtils.isEmpty(modelTyp)) {
			throw new BaseException(
					BaseExceptionConstant.COMMON_0001, "流程业务分类不能为空");
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		// 流程定义KEY和流程定义ID不定义 流程发起的时候会根据模块类型查找唯一流程去发起
		// flowStartParamsDTO.setProcDefKey("");
		// flowStartParamsDTO.setProcDefId("");
		flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
		flowStartParamsDTO.setWordsInTheTable(PrjLnkCompRelInfoConstant.FLOW_S_H_LNK);
		flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext
				.getCurrentUserId()));
		flowStartParamsDTO.setInitiatorNm(CurrentThreadContext
				.getCurrentUserName());
		flowStartParamsDTO
				.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);// 优先级,可以在界面定义
		flowStartParamsDTO.setBusinessType(businessType);// TODO 确认用不用
		flowStartParamsDTO.setModelTyp(modelTyp);// 需要和流程配置中的模块类型匹配
		return flowStartParamsDTO;
	}

	@Override
	public List<PrjLnkCompVO> checkPrjLnkCompByCondition(
			PrjLnkCompQueryCondition qc) throws BaseException {
		if(qc == null){
			return null;
		}
		/*return PrjLnkCompVOTransform.toVOList(this.projectApiService
				.checkPrjLnkCompByCondition(qc));*/
		return PrjLnkCompVOTransform.toVOList(this.prjLnkCompApiService.checkPrjLnkCompByCondition(qc)) ;
	}

	@Override
	public PrjLnkCompVO selectPrjLnkCompByIdAndBuOrgCd(Long id)
			throws BaseException {
		if (StringUtils.isEmpty(id)) {
			BaseLogUtils.newWebLogger("主键参数不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}
		//PrjLnkCompDTO dto = this.projectApiService.selectPrjLnkCompByIdAndBuOrgCd(id, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompByIdAndBuOrgCd(id, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		String ownerCdNm = "";
		Map<String, String> ownerCddictMap = this.sysDictionaryApiService
				.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentBuOrgCd(),
						DictionaryConstant.CODE_PRJ_OWNER_CD);
		if (!ownerCddictMap.isEmpty()) {
			ownerCdNm = ownerCddictMap.get(dto.getOwnerCd());
		}
		dto.setOwnerCdNm(ownerCdNm);// 挂靠公司归属名称
		//查询区域信息
		String rgnPrCd = dto.getRgnPrCd();
		String rgnCyCd = dto.getRgnCyCd();
		StringBuffer rgnNms = new StringBuffer();
		if(StringUtils.isNotBlank(rgnPrCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(rgnPrCd, "11000");
			if(null!=sysRegionDTO){
				rgnNms.append(sysRegionDTO.getRgnNm());
			}
		}
		if(StringUtils.isNotBlank(rgnCyCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(rgnCyCd, "11000");
			if(null!=sysRegionDTO){
				rgnNms.append("-");
				rgnNms.append(sysRegionDTO.getRgnNm());
			}
		}
		PrjLnkCompVO vo = PrjLnkCompVOTransform.toVO(dto);
		vo.setRgnNms(rgnNms.toString());

		// 查询可支持挂靠项目类型
		List<SplCommPropInfoDTO> propInfoDTOList = this.splCommPropInfoApiService.searchSplCommPropInfoByDataIdAndTabNmAndPropTypCd(id,
				PrjLnkCompRelInfoConstant.PRJ_LNK_COMP_TAB_NAME, "001", SplSystemConstant.SPL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, WebBaseConstant.CHANNEL_CD);
		if (CollectionUtils.isNotEmpty(propInfoDTOList)) {
			Map<String, String> propInfoMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, PrjLnkCompRelInfoConstant.SUPP_LNK_PRJ_TYP_DIC_CODE);

			List<String> suppLnkPrjTypCdList = new ArrayList<>();
			StringBuffer propInfo = null;
			StringBuffer propInfoNm = null;
			for (SplCommPropInfoDTO propInfoDTO : propInfoDTOList) {
				suppLnkPrjTypCdList.add(propInfoDTO.getPropInfo());
				if (null == propInfo) {
					propInfo = new StringBuffer();
					propInfo.append(propInfoDTO.getPropInfo());
				} else {
					propInfo.append(";" + propInfoDTO.getPropInfo());
				}
				if (null == propInfoNm) {
					propInfoNm = new StringBuffer();
					propInfoNm.append(propInfoMap.get(propInfoDTO.getPropInfo()));
				} else {
					propInfoNm.append(";" + propInfoMap.get(propInfoDTO.getPropInfo()));
				}
			}
			vo.setSuppPrjTypCdList(suppLnkPrjTypCdList);
			vo.setSuppPrjTypCd(propInfo.toString());
			vo.setSuppPrjTypCdNm(propInfoNm.toString());
		}

		SysFlowSHQueryCondition flowSHQueryCondition = new SysFlowSHQueryCondition();
		flowSHQueryCondition.setDataId(id);
		flowSHQueryCondition.setWordsInTheTable(PrjLnkCompRelInfoConstant.FLOW_S_H_LNK);
		flowSHQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
		flowSHQueryCondition.setBusTyp(FlowConstant.FLOW_MODEL_TYP_LNK);
		flowSHQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
		List<SysFlowSHDTO> sysFlowSHDTOS = this.flowApiService.searchFlowSHDTOList(flowSHQueryCondition);
		if (CollectionUtils.isNotEmpty(sysFlowSHDTOS)) {
			SysFlowSHDTO sysFlowSHDTO = sysFlowSHDTOS.get(0);
			Long startPrjCstMgrId = sysFlowSHDTO.getCrtUsrId();
			String startPrjCstMgrOrgCd = sysFlowSHDTO.getOrgCd();
			if(StringUtils.isNotEmpty(startPrjCstMgrId)){
				SysUsrDTO sysUsrDTO = this.sysUsrApiService.selectSysUsrById(startPrjCstMgrId, SplSystemConstant.FL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD);
				// 查询项目发起人信息
				SysOrgDTO sysOrgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(startPrjCstMgrOrgCd, SplSystemConstant.FL_SYS_CD);
				// 查询项目发起人组织架构信息
				vo.setStartPrjCstMgrId(startPrjCstMgrId);
				if (null != sysUsrDTO) {
					vo.setStartPrjCstMgrNm(sysUsrDTO.getRefRlNm());
					vo.setStartPrjCstMgrTel(sysUsrDTO.getMp());
				}
				vo.setStartPrjCstMgrOrgCd(startPrjCstMgrOrgCd);
				if (null != sysOrgDTO) {
					vo.setStartPrjCstMgrOrgNm(sysOrgDTO.getOrgDispNm());
				}
			}
		}

		return vo;
	}

	@Override
	public List<KeyValueVO> getPrjLnkCompRlRsnTypList() throws BaseException {
		List<KeyValueVO> keyValueList = null;
		List<SysDictionaryDTO> dictionaryList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),
						DictionaryConstant.CODE__PRJ_LNK_COMP_RL_PSN_TYP_CD);
		if (CollectionUtils.isNotEmpty(dictionaryList)) {
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}

		return keyValueList;
	}

	@Override
	public List<KeyValueVO> getCertTypCdList() throws BaseException {
		List<KeyValueVO> keyValueList = null;
		List<SysDictionaryDTO> dictionaryList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd(),
						DictionaryConstant.CODE_GRP_CERT_TYP_CD);
		if (CollectionUtils.isNotEmpty(dictionaryList)) {
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}

		return keyValueList;
	}

	@Override
	public DataResultVO addZkFlowStart(Long compId) throws BaseException {
		DataResultVO resultVO = new  DataResultVO();
		if(null==compId){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"请选择挂靠公司后发起流程！");
		}
		PrjLnkCompDTO dto = new PrjLnkCompDTO();
		FlowStartParamsDTO flowStartParamsDTO = this.getFlowStartParams(FlowConstant.FLOW_BUSINESS_TYP_LNK,FlowConstant.FLOW_MODEL_TYP_LNK);
		flowStartParamsDTO.setOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
		flowStartParamsDTO.setBuOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
		dto.setFlowStartParamsDTO(flowStartParamsDTO);
		dto.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		 
		dto.setId(compId);
		//DataResultDTO resultdto = 	 this.projectApiService.addPrjLnkCompFlowStart(dto);
		DataResultDTO resultdto = this.prjLnkCompApiService.addPrjLnkCompFlowStart(dto);
		resultVO.setData(resultdto.getData());
		resultVO.setInfo(resultdto.getInfo());
		return resultVO;
	}

	@Override
	public List<PrjLinkFlowSHVO> searchPrjLinkFlowList(Long linkId) throws BaseException {
		return PrjLinkFlowSHVOTransform.toVOList(this.prjLnkCompQueryApiService.searchPrjLinkFlowList(linkId,CurrentThreadContext.getCurrentSysCd()));
	}

	@Override
	public List<PrjLnkCompDTO> selectListByNm( PrjLnkCompQueryCondition condition) throws BaseException {
		//return projectApiService.selectListByNm(condition);
		return this.prjLnkCompQueryApiService.selectListByNm(condition) ;
	}
	@Override
	public PrjLnkCompVO selectByIdInFlow(Long lnkCompId, Long modId) throws BaseException {
		// TODO Auto-generated method stub
		
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompByIdAndBuOrgCd(lnkCompId, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		// 通过id查询挂靠公司信息
		String ownerCdNm = "";
		Map<String, String> ownerCddictMap = this.sysDictionaryApiService
				.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentBuOrgCd(),
						DictionaryConstant.CODE_PRJ_OWNER_CD);
		if (!ownerCddictMap.isEmpty()) {
			ownerCdNm = ownerCddictMap.get(dto.getOwnerCd());
		}
		dto.setOwnerCdNm(ownerCdNm);// 挂靠公司归属名称
		//查询区域信息
		// 拼接区域
		String rgnPrCd = dto.getRgnPrCd();
		String rgnCyCd = dto.getRgnCyCd();
		StringBuffer rgnNms = new StringBuffer();
		if(StringUtils.isNotBlank(rgnPrCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(rgnPrCd, "11000");
			if(null!=sysRegionDTO){
				rgnNms.append(sysRegionDTO.getRgnNm());
			}
		}
		if(StringUtils.isNotBlank(rgnCyCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(rgnCyCd, "11000");
			if(null!=sysRegionDTO){
				rgnNms.append("-");
				rgnNms.append(sysRegionDTO.getRgnNm());
			}
		}
		PrjLnkCompVO vo = PrjLnkCompVOTransform.toVO(dto);
		vo.setRgnNms(rgnNms.toString());
		
		LnkCompModDTO lnkCompModDTO = this.lnkCompModApiService.selectById(modId);
		BaseLogUtils.newWebLogger("查询变更主表记录").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.setKeys("lnkCompModDTO", JSON.toJSONString(lnkCompModDTO))
				.info();
		if(null != lnkCompModDTO){
			LnkCompModDtlQC lnkCompModDtlQC = new LnkCompModDtlQC();
			lnkCompModDtlQC.setModId(modId);
			lnkCompModDtlQC.setIsDel(BaseConstant.IS_YESNO_NO);
			List<LnkCompModDtlDTO> modDtlDTOs = this.lnkCompModDtlApiService.searchList(lnkCompModDtlQC );
			BaseLogUtils.newWebLogger("查询变更明细表记录").setLogOperType(LogOperEnum.RESP)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.setKeys("lnkCompModDtlQC", JSON.toJSONString(lnkCompModDtlQC))
					.setKeys("modDtlDTOs", JSON.toJSONString(modDtlDTOs))
					.info();
			for (LnkCompModDtlDTO lnkCompModDtlDTO : modDtlDTOs) {
				if(lnkCompModDtlDTO.getModAttrFiled().equals("suppPrjTypCd")){
					vo.setSuppPrjTypCd(lnkCompModDtlDTO.getModConAft());
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("regDt")){
					//vo.setRegDtStr(lnkCompModDtlDTO.getModConAft());
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft())){
						vo.setRegDtStr(lnkCompModDtlDTO.getModConAft());
						vo.setRegDt(DateUtils.formatDate(new Date(lnkCompModDtlDTO.getModConAft()), DateUtils.YYYY_MM_DD));
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("expDt")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft())){
						vo.setExpDt(DateUtils.formatDate(new Date(lnkCompModDtlDTO.getModConAft()), DateUtils.YYYY_MM_DD));
						vo.setExpDtStr(lnkCompModDtlDTO.getModConAft());
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("isUploadLoa")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft())){
						vo.setIsUploadLoa(Integer.valueOf(lnkCompModDtlDTO.getModConAft()));
					}
				}else if(lnkCompModDtlDTO.getModAttrFiled().equals("isRecycleLoa")){
					if(StringUtils.isNotEmpty(lnkCompModDtlDTO.getModConAft())){
						vo.setIsRecycleLoa(Integer.valueOf(lnkCompModDtlDTO.getModConAft()));
					}
				}else{
					if (lnkCompModDtlDTO.getTabNm().equals(LnkCompConstant.LNK_COMP_FLOW_S_H_LNK_TAB)) {
						Field field = null;
						try {
							// 获取field
							field = BasePrjLnkCompVO.class.getDeclaredField(lnkCompModDtlDTO.getModAttrFiled());
						} catch (NoSuchFieldException e) {
							e.printStackTrace();
						}
						field.setAccessible(true);
						try {
							field.set((Object) vo, lnkCompModDtlDTO.getModConAft());
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						}
					}
				}
			}
		}

		SysFlowSHQueryCondition flowSHQueryCondition = new SysFlowSHQueryCondition();
		flowSHQueryCondition.setDataId(lnkCompId);
		flowSHQueryCondition.setWordsInTheTable(PrjLnkCompRelInfoConstant.FLOW_S_H_LNK);
		flowSHQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
		flowSHQueryCondition.setBusTyp(FlowConstant.FLOW_MODEL_TYP_LNK);
		flowSHQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
		List<SysFlowSHDTO> sysFlowSHDTOS = this.flowApiService.searchFlowSHDTOList(flowSHQueryCondition);
		if (CollectionUtils.isNotEmpty(sysFlowSHDTOS)) {
			SysFlowSHDTO sysFlowSHDTO = sysFlowSHDTOS.get(0);
			Long startPrjCstMgrId = sysFlowSHDTO.getCrtUsrId();
			String startPrjCstMgrOrgCd = sysFlowSHDTO.getOrgCd();
			if(StringUtils.isNotEmpty(startPrjCstMgrId)){
				SysUsrDTO sysUsrDTO = this.sysUsrApiService.selectSysUsrById(startPrjCstMgrId, SplSystemConstant.FL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD);
				SysOrgDTO sysOrgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(startPrjCstMgrOrgCd, SplSystemConstant.FL_SYS_CD);
				vo.setStartPrjCstMgrId(startPrjCstMgrId);
				if (null != sysUsrDTO) {
					vo.setStartPrjCstMgrNm(sysUsrDTO.getRefRlNm());
					vo.setStartPrjCstMgrTel(sysUsrDTO.getMp());
				}
				vo.setStartPrjCstMgrOrgCd(startPrjCstMgrOrgCd);
				if (null != sysOrgDTO) {
					vo.setStartPrjCstMgrOrgNm(sysOrgDTO.getOrgDispNm());
				}
			}
		}

		BaseLogUtils.newWebLogger("获取挂靠公司数据详情").setLogOperType(LogOperEnum.RESP)
				.setSysCd(CurrentThreadContext.getCurrentSysCd())
				.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
				.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
				.setWarning(false)
				.setKeys("PrjLnkCompVO", JSON.toJSONString(vo))
				.info();
		return vo;
	}
	@Override
	public boolean checkLnkCompFLowStatus(Long id, boolean isCheckNoStartedFlow) throws BaseException {
		boolean flag = false;
		//boolean b = false ;
		LnkCompModQC qc = new LnkCompModQC();
		qc.setLnkCompId(id);
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		qc.setIsValid(BaseConstant.IS_YESNO_YES);
		List<LnkCompModDTO> searchList = this.lnkCompModApiService.searchList(qc );
		
		if(isCheckNoStartedFlow){
			qc.setFlowTyp(BaseConstant.IS_YESNO_YES);
			qc.setFlowStatus(BaseConstant.IS_YESNO_YES);
			List<LnkCompModDTO> startedFLowList = this.lnkCompModApiService.searchList(qc );
			if(CollectionUtils.isNotEmpty(startedFLowList)){

				List<Long> dataIds = new ArrayList<>();
				for (LnkCompModDTO lnkCompModDTO : startedFLowList) {
					dataIds.add(lnkCompModDTO.getId());
				}
				//审核状态 LIST
				List<String> audStsCdList = new ArrayList<>(4);
				audStsCdList.add(SplAudStsCdEnum.CHECKING.getStatus());
				audStsCdList.add(SplAudStsCdEnum.REJECT.getStatus());
				//业务类型 LIST
				//List<String> busTypCdList = new ArrayList<>(2);
				//busTypCdList.add("031");
				//busTypCdList.add("039");
		
				//查询流程历史
				SysFlowSHQueryCondition shQueryCondition = new SysFlowSHQueryCondition();
				//shQueryCondition.setDataId(id);
				shQueryCondition.setDataIdList(dataIds);
				//shQueryCondition.setBusTypList(busTypCdList);
				shQueryCondition.setWordsInTheTable("LNK");
				shQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
				shQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
				shQueryCondition.setAudStsCdList(audStsCdList);
				try{
					List<SysFlowSHDTO> sysFlowSHDTOs = this.flowQueryApiService.searchFlowSHList(shQueryCondition);
					if(CollectionUtils.isNotEmpty(sysFlowSHDTOs)){
						flag = true ;
						BaseLogUtils.newWebLogger("挂靠公司存在工商变更流程").setLogOperType(LogOperEnum.REQ)
								.setSysCd(CurrentThreadContext.getCurrentSysCd())
								.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
								.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
								.setWarning(false)
								.setKeys("sysFlowSHDTOs", JSON.toJSONString(sysFlowSHDTOs))
								.warn(LogExceptionEnum.COMMON_CODE_0001);
					}
				}catch (RpcException rpc){
					flag = true ;
					BaseLogUtils.newWebLogger("挂靠公司查询流程历史远程调用异常RPCException").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
							.setWarning(false)
							.setThrowable(rpc)
							.warn(LogExceptionEnum.COMMON_CODE_0001);
				}catch (BaseException be){
					flag = true ;
					BaseLogUtils.newWebLogger("挂靠公司查询流程历史,业务异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
							.setWarning(false)
							.setThrowable(be)
							.warn(LogExceptionEnum.COMMON_CODE_0001);
				}catch (Exception e){
					flag = true ;
					BaseLogUtils.newWebLogger("挂靠公司查询流程历史,系统异常").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
							.setWarning(false)
							.setThrowable(e)
							.error(LogExceptionEnum.COMMON_CODE_0099);
				}
			
			}
			/*qc = new LnkCompModQC();
			qc.setLnkCompId(id);
			qc.setIsDel(BaseConstant.IS_YESNO_NO);
			qc.setIsValid(BaseConstant.IS_YESNO_YES);*/
			qc.setFlowTyp(BaseConstant.IS_YESNO_YES);
			qc.setFlowStatus(BaseConstant.IS_YESNO_NO);
			List<LnkCompModDTO> noStartedFLowList = this.lnkCompModApiService.searchList(qc );
			if(CollectionUtils.isNotEmpty(noStartedFLowList)){
				flag = true ;
			}
			return flag ;	
		}
		
		if(CollectionUtils.isNotEmpty(searchList)){
			List<Long> dataIds = new ArrayList<>();
			for (LnkCompModDTO lnkCompModDTO : searchList) {
				dataIds.add(lnkCompModDTO.getId());
			}
			//审核状态 LIST
			List<String> audStsCdList = new ArrayList<>(4);
			audStsCdList.add(SplAudStsCdEnum.CHECKING.getStatus());
			audStsCdList.add(SplAudStsCdEnum.REJECT.getStatus());
			//业务类型 LIST
			List<String> busTypCdList = new ArrayList<>(2);
			//busTypCdList.add("031");
			//busTypCdList.add("032");
	
			//查询流程历史
			SysFlowSHQueryCondition shQueryCondition = new SysFlowSHQueryCondition();
			//shQueryCondition.setDataId(id);
			shQueryCondition.setDataIdList(dataIds);
			//shQueryCondition.setBusTypList(busTypCdList);
			shQueryCondition.setWordsInTheTable("LNK");
			shQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
			shQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
			shQueryCondition.setAudStsCdList(audStsCdList);
			try{
				List<SysFlowSHDTO> sysFlowSHDTOs = this.flowQueryApiService.searchFlowSHList(shQueryCondition);
				if(CollectionUtils.isNotEmpty(sysFlowSHDTOs)){
					flag = true ;
					BaseLogUtils.newWebLogger("挂靠公司存在变更流程").setLogOperType(LogOperEnum.REQ)
							.setSysCd(CurrentThreadContext.getCurrentSysCd())
							.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
							.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
							.setWarning(false)
							.setKeys("sysFlowSHDTOs", JSON.toJSONString(sysFlowSHDTOs))
							.warn(LogExceptionEnum.COMMON_CODE_0001);
				}
			}catch (RpcException rpc){
				flag = true ;
				BaseLogUtils.newWebLogger("查询挂靠公司流程历史远程调用异常RPCException").setLogOperType(LogOperEnum.REQ)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.setThrowable(rpc)
						.warn(LogExceptionEnum.COMMON_CODE_0001);
			}catch (BaseException be){
				flag = true ;
				BaseLogUtils.newWebLogger("获取挂靠公司流程历史,业务异常").setLogOperType(LogOperEnum.REQ)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.setThrowable(be)
						.warn(LogExceptionEnum.COMMON_CODE_0001);
			}catch (Exception e){
				flag = true ;
				BaseLogUtils.newWebLogger("获取挂靠公司流程历史,系统异常").setLogOperType(LogOperEnum.REQ)
						.setSysCd(CurrentThreadContext.getCurrentSysCd())
						.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
						.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
						.setWarning(false)
						.setThrowable(e)
						.error(LogExceptionEnum.COMMON_CODE_0099);
			}
		}
		return flag;
	}

	@Override
	public void checkLnkFiles(HttpServletRequest request) throws BaseException{
		String fileParams = request.getParameter("fileParams");
		String ownerCd = request.getParameter("ownerCd");
		String cfgCd;
		String sysCd;
		if (StringUtils.isEmpty(ownerCd)) {// 挂靠公司默认归属第三方
			cfgCd = LnkCompFileCfgEnum.PRJ029.getCode();
			sysCd = LnkCompFileCfgEnum.PRJ029.getSysCd();
		} else {
			if ("1".equals(ownerCd)) {
				cfgCd = LnkCompFileCfgEnum.PRJ030.getCode();
				sysCd = LnkCompFileCfgEnum.PRJ030.getSysCd();
			} else if ("2".equals(ownerCd)) {
				cfgCd = LnkCompFileCfgEnum.PRJ029.getCode();
				sysCd = LnkCompFileCfgEnum.PRJ029.getSysCd();
			} else {
				cfgCd = LnkCompFileCfgEnum.PRJ032.getCode();
				sysCd = LnkCompFileCfgEnum.PRJ032.getSysCd();
			}
		}
		SysUlDatCfgDtlQueryCondition ulDatCfgDtlQueryCondition = new SysUlDatCfgDtlQueryCondition();
		ulDatCfgDtlQueryCondition.setCfgCd(cfgCd);
		ulDatCfgDtlQueryCondition.setIsDel(BaseConstant.IS_YESNO_NO);
		ulDatCfgDtlQueryCondition.setSysCd(sysCd);
		ulDatCfgDtlQueryCondition.setOrgCd(SplSystemConstant.DEFAULT_ORG_CD);
		List<SysUlDatCfgDtlDTO> uploadCfgDtlDTOList = this.sysUlDatCfgDtlApiService.srearchSyUlDatCfgDtlList(ulDatCfgDtlQueryCondition);

		Map<String, Integer> fileCfgDtlCdAndNumMap = new HashMap<>();

		List<SysUlFilesRecVO> filesForPage = JSON.parseArray(fileParams, SysUlFilesRecVO.class);
		if (StringUtils.isEmpty(fileParams)) {
			throw new BaseException("请上传附件信息");
		} else {
			if (!(filesForPage.size() > 0)) {
				throw new BaseException("请上传附件信息");
			}
		}
		if (CollectionUtils.isNotEmpty(filesForPage)) {
			for (SysUlFilesRecVO sysUlFilesRecVO : filesForPage) {
				if (StringUtils.isEmpty(fileCfgDtlCdAndNumMap.get(sysUlFilesRecVO.getCfgDtlCd()))) {
					fileCfgDtlCdAndNumMap.put(sysUlFilesRecVO.getCfgDtlCd(), 1);
				} else {
					fileCfgDtlCdAndNumMap.put(sysUlFilesRecVO.getCfgDtlCd(), fileCfgDtlCdAndNumMap.get(sysUlFilesRecVO.getCfgDtlCd()) + 1);
				}
			}
		}

		for (SysUlDatCfgDtlDTO sysUlDatCfgDtlDTO : uploadCfgDtlDTOList) {
			//校验是否必传
			if (StringUtils.isNotEmpty(sysUlDatCfgDtlDTO.getIsMust()) && 1 == sysUlDatCfgDtlDTO.getIsMust()) {
				if (!fileCfgDtlCdAndNumMap.containsKey(sysUlDatCfgDtlDTO.getCfgDtlCd())) {
					throw new BaseException("请上传" + sysUlDatCfgDtlDTO.getDatNm());
				}
			}

			//校验上传数量
			if (StringUtils.isNotEmpty(sysUlDatCfgDtlDTO.getMaxNum()) && 0 != sysUlDatCfgDtlDTO.getMaxNum()) {
				if (sysUlDatCfgDtlDTO.getMaxNum() < fileCfgDtlCdAndNumMap.get(sysUlDatCfgDtlDTO.getCfgDtlCd())) {
					throw new BaseException(sysUlDatCfgDtlDTO.getDatNm() + "只能上传" + sysUlDatCfgDtlDTO.getMaxNum() + "份");
				}
			}
		}
	}
	@Override
	public PrjLnkCompVO selectPrjLnkCompByIdAndIsMask(Long id, int isMask) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			BaseLogUtils.newWebLogger("主键参数不能为空!").setLogOperType(LogOperEnum.REQ)
					.setSysCd(CurrentThreadContext.getCurrentSysCd())
					.setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
					.setBussinessId(BusinessIdConstant.LOG_SQOT_MANAGER_CD)
					.setWarning(false)
					.warn(LogExceptionEnum.COMMON_CODE_0002);
			return null;
		}
		//PrjLnkCompDTO dto = this.projectApiService.selectPrjLnkCompByIdAndBuOrgCd(id, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		//PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.selectPrjLnkCompByIdAndBuOrgCd(id, CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		PrjLnkCompDTO dto = this.prjLnkCompQueryApiService.searchPrjLnkCompByMask(id, isMask, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		String ownerCdNm = "";
		Map<String, String> ownerCddictMap = this.sysDictionaryApiService
				.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
						CurrentThreadContext.getCurrentBuOrgCd(),
						DictionaryConstant.CODE_PRJ_OWNER_CD);
		if (!ownerCddictMap.isEmpty()) {
			ownerCdNm = ownerCddictMap.get(dto.getOwnerCd());
		}
		dto.setOwnerCdNm(ownerCdNm);// 挂靠公司归属名称
		//查询区域信息
		String rgnPrCd = dto.getRgnPrCd();
		String rgnCyCd = dto.getRgnCyCd();
		StringBuffer rgnNms = new StringBuffer();
		if(StringUtils.isNotBlank(rgnPrCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(rgnPrCd, "11000");
			if(null!=sysRegionDTO){
				rgnNms.append(sysRegionDTO.getRgnNm());
			}
		}
		if(StringUtils.isNotBlank(rgnCyCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(rgnCyCd, "11000");
			if(null!=sysRegionDTO){
				rgnNms.append("-");
				rgnNms.append(sysRegionDTO.getRgnNm());
			}
		}
		PrjLnkCompVO vo = PrjLnkCompVOTransform.toVO(dto);
		vo.setRgnNms(rgnNms.toString());

		// 查询可支持挂靠项目类型
		List<SplCommPropInfoDTO> propInfoDTOList = this.splCommPropInfoApiService.searchSplCommPropInfoByDataIdAndTabNmAndPropTypCd(id,
				PrjLnkCompRelInfoConstant.PRJ_LNK_COMP_TAB_NAME, "001", SplSystemConstant.SPL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, WebBaseConstant.CHANNEL_CD);
		if (CollectionUtils.isNotEmpty(propInfoDTOList)) {
			Map<String, String> propInfoMap = this.sysDictionaryApiService.searchGroupToMap(SplSystemConstant.SPL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD, PrjLnkCompRelInfoConstant.SUPP_LNK_PRJ_TYP_DIC_CODE);

			List<String> suppLnkPrjTypCdList = new ArrayList<>();
			StringBuffer propInfo = null;
			StringBuffer propInfoNm = null;
			for (SplCommPropInfoDTO propInfoDTO : propInfoDTOList) {
				suppLnkPrjTypCdList.add(propInfoDTO.getPropInfo());
				if (null == propInfo) {
					propInfo = new StringBuffer();
					propInfo.append(propInfoDTO.getPropInfo());
				} else {
					propInfo.append(";" + propInfoDTO.getPropInfo());
				}
				if (null == propInfoNm) {
					propInfoNm = new StringBuffer();
					propInfoNm.append(propInfoMap.get(propInfoDTO.getPropInfo()));
				} else {
					propInfoNm.append(";" + propInfoMap.get(propInfoDTO.getPropInfo()));
				}
			}
			vo.setSuppPrjTypCdList(suppLnkPrjTypCdList);
			vo.setSuppPrjTypCd(propInfo.toString());
			vo.setSuppPrjTypCdNm(propInfoNm.toString());
		}

		SysFlowSHQueryCondition flowSHQueryCondition = new SysFlowSHQueryCondition();
		flowSHQueryCondition.setDataId(id);
		flowSHQueryCondition.setWordsInTheTable(PrjLnkCompRelInfoConstant.FLOW_S_H_LNK);
		flowSHQueryCondition.setSysCd(SplSystemConstant.FL_SYS_CD);
		flowSHQueryCondition.setBusTyp(FlowConstant.FLOW_MODEL_TYP_LNK);
		flowSHQueryCondition.setStatus(BaseConstant.IS_YESNO_YES);
		List<SysFlowSHDTO> sysFlowSHDTOS = this.flowApiService.searchFlowSHDTOList(flowSHQueryCondition);
		if (CollectionUtils.isNotEmpty(sysFlowSHDTOS)) {
			SysFlowSHDTO sysFlowSHDTO = sysFlowSHDTOS.get(0);
			Long startPrjCstMgrId = sysFlowSHDTO.getCrtUsrId();
			String startPrjCstMgrOrgCd = sysFlowSHDTO.getOrgCd();
			if(StringUtils.isNotEmpty(startPrjCstMgrId)){
				SysUsrDTO sysUsrDTO = this.sysUsrApiService.selectSysUsrById(startPrjCstMgrId, SplSystemConstant.FL_SYS_CD, SplSystemConstant.DEFAULT_ORG_CD);
				SysOrgDTO sysOrgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(startPrjCstMgrOrgCd, SplSystemConstant.FL_SYS_CD);
				vo.setStartPrjCstMgrId(startPrjCstMgrId);
				if (null != sysUsrDTO) {
					vo.setStartPrjCstMgrNm(sysUsrDTO.getRefRlNm());
					vo.setStartPrjCstMgrTel(sysUsrDTO.getMp());
				}
				vo.setStartPrjCstMgrOrgCd(startPrjCstMgrOrgCd);
				if (null != sysOrgDTO) {
					vo.setStartPrjCstMgrOrgNm(sysOrgDTO.getOrgDispNm());
				}
			}
		}

		return vo;
	}
	@Override
	public boolean modifyLnkLoa(PrjLnkCompVO entity) throws BaseException {
		// TODO Auto-generated method stub
		return this.prjLnkCompApiService.modifyLnkCompLoa(PrjLnkCompVOTransform.toDTO(entity),CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public DataResultDTO selectRiskLnkList(Long prjId, String vehNo, Long splId) throws BaseException {
		DataResultDTO resultDTO = new DataResultDTO(BaseConstant.IS_YESNO_YES,"成功");
		resultDTO.setCode(BaseConstant.IS_YESNO_NO_STR);//没有私户
		BaseLogUtils.info(logger,"selectRiskLnkList","客户征信绑定挂靠数据.请求参数prjId=" + prjId);
		List<RcCstChannelInfoDTO> lnkList = new ArrayList<RcCstChannelInfoDTO>();
		RcCstBscInfoCarQC qc = new RcCstBscInfoCarQC();
		PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		Long cstId = prjBscInfoVO.getCstId();
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		//获取购车类型
		SysCdMapDQueryCondition condition = new SysCdMapDQueryCondition();
		condition.setOrgCd(prjBscInfoVO.getBuOrgCd());
		condition.setSysCd(WebBaseConstant.SYS_SYS_CD);
		condition.setmTypCd(PrjBscInfoConstant.SYS_CD_MAP_D_M_TYP);
		condition.setsCode(prjTypCd);
		List<SysCdMapDDTO> sysCdMapDDTOs = this.sysCdMapApiService.searchSysCdMapDWithTargetList(condition);
		if (CollectionUtils.isEmpty(sysCdMapDDTOs)) {
			throw new BaseException("客户征信绑定挂靠数据.获取购车类型失败");
		}
		SysCdMapDDTO sysCdMapDDTO = sysCdMapDDTOs.get(0);
		BaseLogUtils.info(logger, "selectRiskLnkList", "客户征信绑定挂靠数据.sysCdMapDDTO=" + JSON.toJSONString(sysCdMapDDTO));
		qc.setPrdTypCd(sysCdMapDDTO.getTCode());
		if(PrjBscInfoConstant.PRJ_TYP_CD_CDDYWUL.equals(prjTypCd)){
			qc.setCarNo(vehNo);
		}
		PrjPrdBscInfoQueryCondition prjPrdBscInfoQueryCondition = new PrjPrdBscInfoQueryCondition();
		prjPrdBscInfoQueryCondition.setPrjId(prjId);
		List<PrjPrdBscInfoVO> prjPrdBscInfoVOS = this.prjPrdBscInfoService.searchList(prjPrdBscInfoQueryCondition);
		if(CollectionUtils.isEmpty(prjPrdBscInfoVOS)){
            if(splId != null){
                qc.setSplId(splId);
            }else{
                qc.setCstMgrId(prjBscInfoVO.getCstMgrId());
            }
		}else{
            PrjPrdBscInfoVO prjPrdBscInfoVO = prjPrdBscInfoVOS.get(0);
            String receiveTypeCd = prjPrdBscInfoVO.getReceiveTypeCd();
            if(CapitalConstant.CODE_PAYEE_TYP_CD_1.equals(receiveTypeCd)){
                qc.setSplId(prjPrdBscInfoVO.getSplId());
            }else{
                qc.setCstMgrId(prjBscInfoVO.getCstMgrId());
            }
        }
		CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(cstId);
		String cstTypCd = cstBscInfoVO.getCstTypCd();
		if(CustomerConstant.CST_TYP_CD_NP.equals(cstTypCd)){
			CstNpBscInfoVO cstNpBscInfoVO = this.cstNpBscInfoService.selectById(cstId);
			qc.setCstNm(cstBscInfoVO.getCstNm());
			qc.setCertNo(cstBscInfoVO.getCertNo());
			qc.setMp1(cstNpBscInfoVO.getMp1());
		}else if(CustomerConstant.CST_TYP_CD_CORP.equals(cstTypCd)){
			List<Long> cstIdList = new ArrayList<Long>();
			cstIdList.add(cstId);
			CstCorpTeamQueryCondition teamQc = new CstCorpTeamQueryCondition();
			teamQc.setCstIdList(cstIdList);
			teamQc.setSysCd(SYSCD);
			teamQc.setmTypCd(PrjCstBscInfoConstant.CST_CORP_TEAM_REPR);
			List<CstCorpTeamVO> cstCorpTeamList = this.cstCorpTeamService.searchList(teamQc);
			if (CollectionUtils.isEmpty(cstCorpTeamList)) {
				BaseLogUtils.info(logger, "selectRiskLnkList", "客户征信绑定挂靠数据.法人代表数据异常cstId=" + cstId);
				throw new BaseException("客户征信绑定挂靠数据.法人代表数据异常");
			}
			CstCorpTeamVO cstCorpTeamVO = cstCorpTeamList.get(0);
			qc.setCstNm(cstCorpTeamVO.getMNm());
			qc.setCertNo(cstCorpTeamVO.getCertNo());
			qc.setMp1(cstCorpTeamVO.getMp1());
		}else{
			BaseLogUtils.info(logger, "selectRiskLnkList", "客户征信绑定挂靠数据.未知客户类型cstId=" + cstId);
			throw new BaseException("客户征信绑定挂靠数据.未知客户类型");
		}
		BaseParamDTO baseParamDTO = new BaseParamDTO();
		baseParamDTO.setSysCd(WebBaseConstant.SYS_SYS_CD);
		baseParamDTO.setChannelCd(SplSystemConstant.FL_HELPER_APP_CHL_CD);
		baseParamDTO.setServiceCd(WebBaseConstant.FL_SERVICE_SYS_CD);
		BaseLogUtils.info(logger, "selectRiskLnkList", "客户征信绑定挂靠数据.getRcCstBscInfoList参数qc=" + JSON.toJSONString(qc));
		DataResultDTO rcCstBscInfoList = this.externalRcCstBscInfoSearchApiService.getRcCstBscInfoList(qc, baseParamDTO);
		BaseLogUtils.info(logger, "selectRiskLnkList", "客户征信绑定挂靠数据.getRcCstBscInfoList返回结果rcCstBscInfoList=" + JSON.toJSONString(rcCstBscInfoList));
		if(rcCstBscInfoList != null && rcCstBscInfoList.getSuccess() == BaseConstant.IS_YESNO_YES){
			Object resData = rcCstBscInfoList.getData();
			if(resData != null){
				List<RcCstBscInfoDTO> rcCstBscInfoDTOs = (List<RcCstBscInfoDTO>) (resData);
				if(CollectionUtils.isNotEmpty(rcCstBscInfoDTOs)){
					for (RcCstBscInfoDTO rcCstBscInfoDTO : rcCstBscInfoDTOs) {
						if(StringUtils.isNotEmpty(rcCstBscInfoDTO.getRskLvlCd()) && !((rcCstBscInfoDTO.getRskLvlCd()).equals("3"))){
							List<RcCstChannelInfoDTO> rcCstChannelInfoDTOList = rcCstBscInfoDTO.getRcCstChannelInfoDTOList();
							if(CollectionUtils.isNotEmpty(rcCstChannelInfoDTOList)){
								boolean flag = true;
								for (RcCstChannelInfoDTO rcCstChannelInfo : rcCstChannelInfoDTOList) {
									if(BaseConstant.IS_YESNO_YES == rcCstChannelInfo.getChannelTyp()
											&& BaseConstant.IS_YESNO_NO_STR.equals(rcCstChannelInfo.getLnkType())){
										lnkList.add(rcCstChannelInfo);
										flag = false;
										break;
									}
								}
								if(flag){
									resultDTO.setCode(BaseConstant.IS_YESNO_YES_STR);
								}
							}else{
								resultDTO.setCode(BaseConstant.IS_YESNO_YES_STR);
							}
						}
					}
				}
			}
		}else{
			BaseLogUtils.info(logger,"selectRiskLnkList","客户征信信息异常.cstId=" + cstId);
			throw new BaseException("客户征信信息异常,请核实");
		}
		/**
		 * 挂靠逻辑  取低级 最新
		 */
		if(CollectionUtils.isNotEmpty(lnkList)){
			resultDTO.setData(this.dealLnkData(lnkList));
		}
		BaseLogUtils.info(logger,"selectRiskLnkList","客户征信绑定挂靠数据.结果resultDTO=" + JSON.toJSONString(resultDTO));
		return resultDTO;
	}

	@Override
	public String getRrcCstBscInfoId(Long prjId, Long splId) throws BaseException {
		DataResultDTO resultDTO = new DataResultDTO(BaseConstant.IS_YESNO_YES,"成功");
		resultDTO.setCode(BaseConstant.IS_YESNO_NO_STR);//没有私户
		BaseLogUtils.info(logger,"getRrcCstBscInfoId","客户征信绑定挂靠数据.请求参数prjId=" + prjId);
		List<RcCstChannelInfoDTO> lnkList = new ArrayList<RcCstChannelInfoDTO>();
		RcCstBscInfoCarQC qc = new RcCstBscInfoCarQC();
		PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(Long.valueOf(prjId));
		Long cstId = prjBscInfoVO.getCstId();
		String prjTypCd = prjBscInfoVO.getPrjTypCd();
		//获取购车类型
		SysCdMapDQueryCondition condition = new SysCdMapDQueryCondition();
		condition.setOrgCd(prjBscInfoVO.getBuOrgCd());
		condition.setSysCd(WebBaseConstant.SYS_SYS_CD);
		condition.setmTypCd(PrjBscInfoConstant.SYS_CD_MAP_D_M_TYP);
		condition.setsCode(prjTypCd);
		List<SysCdMapDDTO> sysCdMapDDTOs = this.sysCdMapApiService.searchSysCdMapDWithTargetList(condition);
		if (CollectionUtils.isEmpty(sysCdMapDDTOs)) {
			throw new BaseException("客户征信绑定挂靠数据.获取购车类型失败");
		}
		SysCdMapDDTO sysCdMapDDTO = sysCdMapDDTOs.get(0);
		BaseLogUtils.info(logger, "getRrcCstBscInfoId", "客户征信绑定挂靠数据.sysCdMapDDTO=" + JSON.toJSONString(sysCdMapDDTO));
		qc.setPrdTypCd(sysCdMapDDTO.getTCode());
		PrjPrdBscInfoQueryCondition prjPrdBscInfoQueryCondition = new PrjPrdBscInfoQueryCondition();
		prjPrdBscInfoQueryCondition.setPrjId(prjId);
		List<PrjPrdBscInfoVO> prjPrdBscInfoVOS = this.prjPrdBscInfoService.searchList(prjPrdBscInfoQueryCondition);
		if(CollectionUtils.isEmpty(prjPrdBscInfoVOS)){
			if(splId != null){
				qc.setSplId(splId);
			}else{
				qc.setCstMgrId(prjBscInfoVO.getCstMgrId());
			}
		}else{
			PrjPrdBscInfoVO prjPrdBscInfoVO = prjPrdBscInfoVOS.get(0);
			String receiveTypeCd = prjPrdBscInfoVO.getReceiveTypeCd();
			if(CapitalConstant.CODE_PAYEE_TYP_CD_1.equals(receiveTypeCd)){
				qc.setSplId(prjPrdBscInfoVO.getSplId());
			}else{
				qc.setCstMgrId(prjBscInfoVO.getCstMgrId());
			}
		}
		CstBscInfoVO cstBscInfoVO = this.cstBscInfoService.selectById(cstId);
		String cstTypCd = cstBscInfoVO.getCstTypCd();
		if(CustomerConstant.CST_TYP_CD_NP.equals(cstTypCd)){
			CstNpBscInfoVO cstNpBscInfoVO = this.cstNpBscInfoService.selectById(cstId);
			qc.setCstNm(cstBscInfoVO.getCstNm());
			qc.setCertNo(cstBscInfoVO.getCertNo());
			qc.setMp1(cstNpBscInfoVO.getMp1());
		}else if(CustomerConstant.CST_TYP_CD_CORP.equals(cstTypCd)){
			List<Long> cstIdList = new ArrayList<Long>();
			cstIdList.add(cstId);
			CstCorpTeamQueryCondition teamQc = new CstCorpTeamQueryCondition();
			teamQc.setCstIdList(cstIdList);
			teamQc.setSysCd(SYSCD);
			teamQc.setmTypCd(PrjCstBscInfoConstant.CST_CORP_TEAM_REPR);
			List<CstCorpTeamVO> cstCorpTeamList = this.cstCorpTeamService.searchList(teamQc);
			if (CollectionUtils.isEmpty(cstCorpTeamList)) {
				BaseLogUtils.info(logger, "getRrcCstBscInfoId", "客户征信绑定挂靠数据.法人代表数据异常cstId=" + cstId);
				throw new BaseException("客户征信绑定挂靠数据.法人代表数据异常");
			}
			CstCorpTeamVO cstCorpTeamVO = cstCorpTeamList.get(0);
			qc.setCstNm(cstCorpTeamVO.getMNm());
			qc.setCertNo(cstCorpTeamVO.getCertNo());
			qc.setMp1(cstCorpTeamVO.getMp1());
		}else{
			BaseLogUtils.info(logger, "getRrcCstBscInfoId", "客户征信绑定挂靠数据.未知客户类型cstId=" + cstId);
			throw new BaseException("客户征信绑定挂靠数据.未知客户类型");
		}
		BaseParamDTO baseParamDTO = new BaseParamDTO();
		baseParamDTO.setSysCd(WebBaseConstant.SYS_SYS_CD);
		baseParamDTO.setChannelCd(SplSystemConstant.FL_HELPER_APP_CHL_CD);
		baseParamDTO.setServiceCd(WebBaseConstant.FL_SERVICE_SYS_CD);
		BaseLogUtils.info(logger, "getRrcCstBscInfoId", "客户征信绑定挂靠数据.getRcCstBscInfoList参数qc=" + JSON.toJSONString(qc));
		DataResultDTO rcCstBscInfoList = this.externalRcCstBscInfoSearchApiService.getRcCstBscInfoList(qc, baseParamDTO);
		BaseLogUtils.info(logger, "getRrcCstBscInfoId", "客户征信绑定挂靠数据.getRcCstBscInfoList返回结果rcCstBscInfoList=" + JSON.toJSONString(rcCstBscInfoList));
		if(rcCstBscInfoList != null && rcCstBscInfoList.getSuccess() == BaseConstant.IS_YESNO_YES){
			Object resData = rcCstBscInfoList.getData();
			if(resData != null){
				List<RcCstBscInfoDTO> rcCstBscInfoDTOs = (List<RcCstBscInfoDTO>) (resData);
				RcCstBscInfoDTO dto = Collections.max(rcCstBscInfoDTOs, new maxRskLvlCd());
				return dto.getId().toString();
			}
		}else{
			BaseLogUtils.info(logger,"selectRiskLnkList","客户征信信息异常.cstId=" + cstId);
			throw new BaseException("客户征信信息异常,请核实");
		}
		return null;
	}

	private List<RcCstChannelInfoDTO> dealLnkData( List<RcCstChannelInfoDTO> lnkList) throws BaseException{
		List<RcCstChannelInfoDTO> resList = new ArrayList<RcCstChannelInfoDTO>();
		Map<Long,List<RcCstChannelInfoDTO>> lnkMap = new HashMap<Long,List<RcCstChannelInfoDTO>>();
		for (RcCstChannelInfoDTO rcCstChannelInfoDTO : lnkList) {
			Long channelId = rcCstChannelInfoDTO.getChannelId();
			if(lnkMap.containsKey(channelId)){
				lnkMap.get(channelId).add(rcCstChannelInfoDTO);
			}else{
				List<RcCstChannelInfoDTO> lnkRcList = new ArrayList<RcCstChannelInfoDTO>();
				lnkRcList.add(rcCstChannelInfoDTO);
				lnkMap.put(channelId,lnkRcList);
			}
		}
		if(MapUtils.isNotEmpty(lnkMap)){
			for (Long lnkId : lnkMap.keySet()) {
				List<RcCstChannelInfoDTO> lnks = lnkMap.get(lnkId);
				RcCstChannelInfoDTO dto = Collections.max(lnks, new maxLnkRskLvlCd());
				resList.add(dto);
			}
		}
		return resList;
	}

	class maxLnkRskLvlCd implements Comparator<RcCstChannelInfoDTO> {

		@Override
		public int compare(RcCstChannelInfoDTO o1, RcCstChannelInfoDTO o2) {
			Integer rskLvl1 = 0;
			Integer rskLvl2 = 0;
			if (StringUtils.isNotEmpty(o1.getFinalUserLevel())) {
				if(o1.getFinalUserLevel().equals("4")){
					rskLvl1 = -2;
				}else if(o1.getFinalUserLevel().equals("5")){
					rskLvl1 = -1;
				}else{
					rskLvl1 = Integer.valueOf(o1.getFinalUserLevel());
				}
			}
			if (StringUtils.isNotEmpty(o2.getFinalUserLevel())) {
				if(o2.getFinalUserLevel().equals("4")){
					rskLvl2 = -2;
				}else if(o2.getFinalUserLevel().equals("5")){
					rskLvl2 = -1;
				}else{
					rskLvl2 = Integer.valueOf(o2.getFinalUserLevel());
				}
			}
			return rskLvl1 - rskLvl2 == 0 ? o1.getId().compareTo(o2.getId()) : rskLvl1 - rskLvl2;
		}

	}

	class maxRskLvlCd implements Comparator<RcCstBscInfoDTO> {

		@Override
		public int compare(RcCstBscInfoDTO o1, RcCstBscInfoDTO o2) {
			Integer rskLvl1 = 0;
			Integer rskLvl2 = 0;
			if (StringUtils.isNotEmpty(o1.getRskLvlCd2())) {
				//rskLvl1 = Integer.valueOf(o1.getRskLvlCd2());
				if(o1.getRskLvlCd2().equals("4")){
					rskLvl1 = -2;
				}else if(o1.getRskLvlCd2().equals("5")){
					rskLvl1 = -1;
				}else{
					rskLvl1 = Integer.valueOf(o1.getRskLvlCd2());
				}
			}
			if (StringUtils.isNotEmpty(o2.getRskLvlCd2())) {
				//rskLvl2 = Integer.valueOf(o2.getRskLvlCd());
				if(o2.getRskLvlCd2().equals("4")){
					rskLvl2 = -2;
				}else if(o2.getRskLvlCd2().equals("5")){
					rskLvl2 = -1;
				}else{
					rskLvl2 = Integer.valueOf(o2.getRskLvlCd2());
				}
			}
			return rskLvl1 - rskLvl2 == 0 ? o1.getId().compareTo(o2.getId()) : rskLvl1 - rskLvl2;
		}

	}

}
